<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <style>
        thead tr th{text-align: center!important;}
        tr td{text-align: center!important;}
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-table" lay-filter="seckill-table" id="seckill-table"></table>
                    <script type="text/html" id="table-operate-tool">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-warm" lay-event="editThis">新增秒杀活动</button>
                        </div>
                    </script>
                    <script type="text/html" id="table-operate">
                        <a class="layui-btn layui-btn-sm" lay-event="enter">进入</a>
                        {{#  if(d.status == 1){ }}
                        <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="update">失效</a>
                        {{# }}}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','table'], function(){
        var form = layui.form,table = layui.table,$ = layui.$;

        table.render({
           elem:'#seckill-table',
           url:'/activity/querySeckill',
           page:true,
           toolbar: '#table-operate-tool',
           request:{
               pageName:'current',
               limitName:'size'
            },
            cols:[[
                {field:'id',title:'ID',width:80},
                {field:'name',title:'活动名称',minWidth:200},
                {field:'beginTime',title:'开始时间',minWidth:200,templet:"<div>{{layui.util.toDateString(d.beginTime,'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field:'overTime',title:'结束时间',minWidth:200,templet:"<div>{{layui.util.toDateString(d.overTime,'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field:'createTime',title:'创建时间',minWidth:200,templet:"<div>{{layui.util.toDateString(d.createTime,'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field:'status',title:'状态',width:150,templet:function(d){
                    if(d.status==0){
                        return "<span class='layui-badge'>无效</span>";
                    }else if(d.status==1){
                        return "<span class='layui-badge layui-bg-green'>有效</span>";
                    }}},
                {width:200,title:'操作',align:'center',fixed:'right',toolbar:'#table-operate'}
            ]]
        });

        table.on('toolbar(seckill-table)', function(obj){
            if(obj.event === 'editThis'){
                layer.open({
                    title:'新增秒杀活动',
                    type: 2,
                    area: ['600px', '450px'],
                    content: '/activity/addSeckill?id='
                });
            }
        });

        table.on('tool(seckill-table)',function(obj){
            var data = obj.data;
            if(obj.event === 'enter'){
                console.log(data.id);
                window.location.href = '/activity/seckillDetail?id=' + data.id;
            }else if(obj.event === 'update'){
                layer.confirm('确定操作吗？', function(){
                    $.ajax({
                        url: "/activity/handleSeckillStatus",
                        data: {"id": data.id, 'status': 0},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc,{icon:1});
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc,{icon:2});
                            }
                        }
                    });
                });
            }
        });
    });
</script>
</body>
</html>